#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,j,n,m,flag,min=1000,index1,index2;
	cin>>n>>m;
	getchar();
	int k[n],pre[1005];
	string str[n],name[n];
	for(i=0;i<n;i++) {
		pre[i]=-1;
		k[i]=0;
	}
	for(i=0;i<n;i++){
		min=10000;
		getline(cin,str[i]);  
		k[i]=count(str[i].begin(),str[i].end(),' ');
		name[i]=str[i].substr(k[i]);
		if(i!=0){
			flag=i;
			for(j=0;j<i;j++){
				if(k[j]==k[i]-2){
					if(i-j<min){
						min=i-j;
						flag=j;
					}
				}
			}
			pre[i]=flag;
		}
	}
	string relation,name1,name2;
	int r;
	for(i=0;i<m;i++){
		cin>>name1>>name2>>name2>>relation>>name2>>name2;
		for(j=0;j<n;j++){
			if(name1==name[j]) index1=j;
			else if(name2==name[j]) index2=j;
		}
		if(relation=="child"){
			if(pre[index1]==index2)
				cout<<"True"<<endl;
			else cout<<"False"<<endl;
		}
		else if(relation=="parent"){
			if(pre[index2]==index1)
				cout<<"True"<<endl;
			else cout<<"False"<<endl;
		}
		else if(relation=="ancestor"){
				r=index2;
				while(pre[r]!=-1){
					r=pre[r];
					if(r==index1) break;
				}
				if(r==index1) cout<<"True"<<endl;
				else cout<<"False"<<endl;
		}
		else if(relation=="sibling"){
				if(pre[index1]==pre[index2]) cout<<"True"<<endl;
				else cout<<"False"<<endl;
		}
		else if(relation=="descendant"){
			r=index1;
			while(pre[r]!=-1){
				r=pre[r];
				if(r==index2) break;
			}
			if(r==index2) cout<<"True"<<endl;
			else cout<<"False"<<endl;
		}	
	}
}
